package com.kc.sjwh.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kc.sjwh.dao.JqyjzbDao;
import com.kc.sjwh.entity.po.Jqyjzb;
import com.kc.sjwh.other.Page;
import com.kc.sjwh.other.QueryParam;

/**
 * 警情预警指标Service
 * @author zhouy
 *
 */
@Service
public class JqyjzbService {
	@Autowired
	JqyjzbDao jqyjzbDao;
	
	/**
	 * 获得列表数据
	 * @param p
	 * @return
	 */
	public Page<Jqyjzb> getData(QueryParam p) {
		return jqyjzbDao.getPage(p);
	}
	
	/**
	 * 编辑数据
	 * @param one
	 */
	public void editData(Jqyjzb one){
		jqyjzbDao.update(one, "zbid");
	}
	
	/**
	 * 新增数据
	 * @param one
	 */
	public void addData(Jqyjzb one){
		jqyjzbDao.add(one);
	}
	
	/**
	 * 获取需要编辑的对象
	 * @param req
	 * @param id
	 */
	public Jqyjzb getOneInfo(String id){
		QueryParam p = new QueryParam();
		p.addSqlCondition(" t.zbid = '" + id + "'");
		Jqyjzb one = jqyjzbDao.getOne(p);
		return one;
	}
	
	/**
	 * 获得新数据的Zbid
	 * @return
	 */
	public String getNewZbid(){
		String zbid = "";
		Jqyjzb jqyjzb =  jqyjzbDao.getOne("getNewZbid", new QueryParam());
		zbid = jqyjzb.getZbid();
		long n = Long.parseLong(zbid);
		if(n < 1000){
			int length = zbid.length();
			if(length < 3){
				for(int i = 0 ; i < 3 - length ; i++){
					zbid = "0" + zbid;
				}
			}
		}
		return zbid;
	}
}
